<!--  -->
<template>
  <div class="container">
    <div class="navTab">
      <img src="@/assets/img/icon-search.png" alt="" class="search" />
      <input type="text" placeholder="搜索关键词" class="input" />
    </div>
    <div class="banner">
      <van-swipe :autoplay="3000" indicator-color="#007aff">
        <van-swipe-item v-for="item in slides" :key="item.src">
          <a :href="item.href">
            <img v-lazy="item.src" alt="" />
          </a>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="blank">
      <KPBlank :height="blank.height" :bgcolor="blank.bgcolor"></KPBlank>
    </div>
    <section class="gzh">
      <div class="mask" v-show="showQRcode" @click="hide">
        <div class="modal" @click.stop="show">
          <img src="@/assets/img/topright.png" alt="" class="top-right" />
          <div class="title">关注公众号</div>
          <div class="body">
            <div class="qrcode">
              <img :src="gzh.qrcode" alt="" />
            </div>
          </div>
          <div class="tip">长按二维码识别或截图保存</div>
        </div>
      </div>
      <section class="gzh-left">
        <section class="avatar">
          <img :src="gzh.logo" alt="" />
        </section>
        <section class="info">
          <section class="info-top">
            {{ gzh&&gzh.name }}
          </section>
          <section class="info-bottom">{{ gzh&&gzh.desc }}</section>
        </section>
      </section>
      <section class="gzh-right">
        <section class="gzh-right-btn" @click.stop="show">关注</section>
      </section>
    </section>
    <div class="index-section-box">
      <div class="index-section-title">
        <div class="index-section-title-text">{{ courseInfo.title }}</div>
        <div class="more" @click.stop="goToAllCourse">
          <span>查看全部</span>
        </div>
      </div>
      <div class="index-section-body">
        <KPCourseItem
          v-for="i in courseInfo.items"
          :key="i.id"
          :item="i"
          :token="token"
        ></KPCourseItem>
      </div>
    </div>
    <TechSupport></TechSupport>
    <kp-foot-nav type="home"></kp-foot-nav>
  </div>
</template>

<script>
import Vue from "vue";
import { Swipe, SwipeItem, Lazyload } from "vant";
import KPBlank from "@/components/KPBlank.vue";
import KPCourseItem from "@/components/KPCourseItem.vue";
import TechSupport from "@/components/TechSupport.vue";
import KPFootNav from "@/components/kp-foot-nav.vue";
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Lazyload);
export default {
  components: {
    KPBlank,
    KPCourseItem,
    TechSupport,
    "kp-foot-nav": KPFootNav,
  },
  data() {
    return {
      blocks: [],
      slides: [],
      navs: [],
      blank: {},
      gzh: {},
      showQRcode: false,
      courseInfo: {},
      token: localStorage.getItem("h5-token")||"",
    };
  },
  computed: {},
  watch: {},
  methods: {
    goToAllCourse: function () {
      this.$router.push({
        path: "/vod",
      });
    },
    hide: function () {
      this.showQRcode = false;
    },
    show: function () {
      this.showQRcode = true;
    },
  },
  async created() {
    let res = await this.$request.get("/api/v2/viewBlock/page/blocks", {
      params: {
        platform: "h5",
        page_name: "h5-page-index",
      },
    });
    this.blocks = res.data;
    res.data.forEach((item) => {
      if (item.sign === "slider") {
        this.slides = item.config_render;
      }
      if (item.sign === "grid-nav") {
        this.navs = item.config_render;
      }
      if (item.sign === "blank") {
        this.blank = item.config_render;
      }
      if (item.sign === "h5-gzh-v1") {
        this.gzh = item.config_render;
      }
      if (item.sign === "h5-vod-v1") {
        this.courseInfo = item.config_render;
      }
    });
    console.log(this.slides);
  },
  mounted() {},
  beforeCreate() {}, 
  beforeMount() {}, 
  beforeUpdate() {}, 
  updated() {}, 
  beforeDestroy() {}, 
  destroyed() {}, 
  activated() {}, 
};
</script>
<style lang='less' scoped>
.container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #f6f6f6;
  overflow-x: hidden;
  overflow-y: scroll;
  .navTab {
    width: 100%;
    height: 1.333333rem;
    background: #fff;
    position: relative;
    display: flex;
    padding: 0.213333rem 0.4rem;
    .search {
      width: 0.426667rem;
      height: 0.426667rem;
      position: absolute;
      top: 0.453333rem;
      left: 0.986667rem;
      cursor: pointer;
    }

    .input {
      width: 100%;
      height: 0.906667rem;
      background: #f5f5f5;
      border-radius: 0.453333rem;
      outline: none;
      border: none;
      padding-left: 1.333333rem;
      font-size: 0.373333rem;
    }
  }
  .banner {
    width: 100%;
    margin-top: 0;
    padding: 0.266667rem 0.4rem;
    height: 3.6rem;
    overflow: hidden;
    background: #fff;
    img {
      width: 100%;
      height: 3.066667rem;
    }
  }
  .navs {
    display: flex;
    padding: 0.133333rem;
    background-color: white;
    .navs-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      img {
        height: 1.333333rem;
        width: 1.333333rem;
      }

      .name {
      }
    }
  }
  .gzh {
    margin-top: 0.266667rem;
    width: 100%;
    height: auto;
    padding: 15px;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .mask {
      position: fixed;
      z-index: 999;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.6);
      .modal {
        position: fixed;
        z-index: 999;
        width: 200px;
        height: 236px;
        top: calc(50% - 118px);
        left: calc(50% - 100px);
        background-color: #fff;
        border-radius: 8px;
        overflow: hidden;
        -webkit-animation: window-open 0.3s;
        animation: window-open 0.3s;
        display: flex;
        flex-direction: column;
        .top-right {
          position: absolute;
          top: 0.08rem;
          right: 0;
          width: 1.706667rem;
          height: 1.786667rem;
        }

        .title {
          width: 100%;
          margin-top: 20px;
          height: 14px;
          font-size: 14px;
          font-weight: 500;
          color: #333;
          line-height: 14px;
          text-align: center;
        }

        .body {
          width: 100%;
          margin-top: 20px;
          height: 120px;
          display: flex;
          justify-content: center;
          .qrcode {
            width: 3.2rem;
            height: 3.2rem;
            img {
              width: 3.2rem;
              height: 3.2rem;
            }
          }
        }

        .tip {
          width: 100%;
          margin-top: 0.533333rem;
          height: 0.32rem;
          font-size: 0.32rem;
          font-weight: 400;
          color: #999;
          line-height: 0.32rem;
          text-align: center;
        }
      }
    }
    .gzh-left {
      display: flex;
      align-items: center;
      .avatar {
        margin-right: 0.266667rem;
        img {
          width: 1.333333rem;
          height: 1.333333rem;
          border-radius: 50%;
        }
      }

      .info {
        .info-top {
          width: 100%;
          height: 20px;
          font-size: 15px;
          font-weight: 500;
          color: #171923;
          line-height: 20px;
          margin-top: 5px;
          overflow: hidden;
        }

        .info-bottom {
          width: 100%;
          height: 12px;
          font-size: 12px;
          font-weight: 400;
          color: #999;
          line-height: 12px;
          margin-top: 8px;
          overflow: hidden;
        }
      }
    }

    .gzh-right {
      .gzh-right-btn {
        width: 1.546667rem;
        height: 0.64rem;
        line-height: 0.64rem;
        background: #3ca7fa;
        border-radius: 12px;
        font-size: 0.373333rem;
        font-weight: 400;
        color: #fff;
        text-align: center;
      }
    }
  }
  .index-section-box {
    width: 100%;
    // margin-top: 0.266667rem;
    background: #fff;
    padding: 0.666667rem 0.4rem 0.533333rem 0.4rem;
    display: flex;
    flex-direction: column;
    .index-section-title {
      width: 100%;
      height: 0.506667rem;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0.666667rem;
      .index-section-title-text {
        height: 0.506667rem;
        font-size: 0.506667rem;
        font-weight: 600;
        color: #333;
        line-height: 0.506667rem;
      }

      .more {
        display: inline-block;
        width: auto;
        height: 0.346667rem;
        font-size: 0.346667rem;
        font-weight: 400;
        color: #999;
        line-height: 0.346667rem;
        cursor: pointer;
        span {
        }
      }
    }

    .index-section-body {
      width: 100%;
    }
  }
}
</style>